<?php
/*************************************************************************
Class Pick_Dao_Product
----------------------------------------------------------------
Pick CMS Project
Company: Pick Co., Ltd                                  
Email: admin@pick.vn                                    
Last updated: 08/08/2011
**************************************************************************/
class Pick_Dao_Product extends Pick_Core_Objects {
	function Pick_Dao_Product($database = '') {
		if(!$database) {
			global $db;
			$this->_db = $db;
		} else $this->_db = $database;
		$this->objectInfo 	= 'Pick_Dao_ProductInfo';
		$this->typeId = " AND typeid = 2";		
		$this->table = DB_PREFIX."product";
	}
/*-----------------------------------------------------------------------*
* Function: getFiveObjectsFromCIdForHome
* Parameter: WHERE condition
* Return: Array of Info objects
*-----------------------------------------------------------------------*/
	function getFiveObjectsFromCIdForHome($cid) {
		return $this->getObjects(1, 'cid = "' . $cid . '" AND home = 1 AND status = 1', "", 5);
	}
/*-----------------------------------------------------------------------*
* Function: getObjects
* Parameter: WHERE $key
* Return: Array of Info objects
*-----------------------------------------------------------------------*/   	
	function getObjectProductsFull($page = 1, $strIdSubCategory = "", $khuvuc = "", $sort = array(), $items_per_page = 0) {
		$condition = "1=1";
		
		// Get Subcategory ID
		$productcategorysub = new Pick_Dao_ProductCategorySub();
		$arrProductCategorySub = $productcategorysub->getArrIdProducts("categoryid IN(".$strIdSubCategory.")");
		
		// Get Area ID
		$productarea = new Pick_Dao_ProductArea();
		$area = new Pick_Dao_Area();
		$objArea = $area->getObjectFromSlug($khuvuc);
		$arrProductArea = array();
		if(is_object($objArea)){
			$arrProductArea = $productarea->getArrIdProducts("categoryid IN(".$objArea->getField('id').")");
		}
		
		// Kiem tra dieu kien dua vao, neu co 2 thi loc theo 2, neu co mot trong 2 thi lay mot trong 2
		if($strIdSubCategory != ""&&$khuvuc != "")
			$arrProduct = array_unique(array_intersect($arrProductCategorySub, $arrProductArea));
		elseif($strIdSubCategory != "")
			$arrProduct = $arrProductCategorySub;
		elseif($khuvuc != "")
			$arrProduct = $arrProductArea;
			
		$strIdProduct = implode(",",$arrProduct);
		if($strIdProduct!=""){
			return $this->getObjects($page, "id IN(".$strIdProduct.")", $sort, $items_per_page);
		}
		return;
	}
					
}
?>